﻿using One.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.DynamicData;

namespace OneWeb.DbContexts
{
    public class OneDataContext : DbContext
    {
        public OneDataContext() : base ("connectionString")
        {
            Database.Log = s => Debug.WriteLine(s);
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<OneDataContext>());
        }

        public DbSet<Content> Contents { get; set; }

        public DbSet<Article> Articles { get; set; }

        public DbSet<Music> Musics { get; set; }

        public DbSet<Movie> Movies { get; set; }

        public DbSet<Author> Authors { get; set; }

        public DbSet<Serial> Serials { get; set; }

        public DbSet<Answer> Answers { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //modelBuilder.Entity<Author>()
            //    .HasMany(a => a.Answers)
            //    .WithRequired(a => a.Author)
            //    .HasForeignKey(a => a.AuthorId)
            //    .WillCascadeOnDelete(false);

            //modelBuilder.Entity<Author>()
            //    .HasMany(a => a.Asks)
            //    .WithRequired(a => a.Asker)
            //    .HasForeignKey(a => a.AskerId)
            //    .WillCascadeOnDelete(false);
        } 
    }
}